{% extends 'template.html' %}
{% load staticfiles %}

{% block username %}
    {{ request.user.username }}
{% endblock %}

{% block content %}
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">任务执行记录-{{ salt_task.name }}</h1>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <div class="btn-group">
                            <a href="javascript:" onclick="self.location=document.referrer;" class="btn btn-success">返回</a>
                        </div>
                    </div>
                    <div class="panel-body">
                        {% if history %}
                            <table id="mytable" width="100%" cellspacing="0"
                                   class="table table-striped table-hover">
                                <thead>
                                <tr>
                                    <th>任务名称</th>
                                    <th>执行时间</th>
                                    <th>执行人</th>
                                    <th>执行主机 IP 列表</th>
                                    <th>执行结果</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                {% for h in history %}
                                    <tr>
                                        <td>{{ salt_task.name }}</td>
                                        <td>{{ h.execute_time|date:"Y-m-d H:i:s" }}</td>
                                        <td>{{ h.execute_user.username }}</td>
                                        <td>{{ h.format_run_target }}</td>
                                        <td>
                                            {% if h.get_execute_result == '全部失败' %}
                                                <label class="label label-danger">{{ h.get_execute_result }}</label>
                                            {% elif h.get_execute_result == '部分失败' %}
                                                <label class="label label-warning">{{ h.get_execute_result }}</label>
                                            {% else %}
                                                <label class="label label-success">{{ h.get_execute_result }}</label>
                                            {% endif %}
                                        </td>
                                        <td>
                                            <button class="btn btn-sm btn-info" onclick="view_detail({{ h.id }})">
                                                查看所有主机执行结果
                                            </button>
                                            <button class="btn btn-sm btn-success"
                                                    onclick="view_run_targets({{ h.id }})">查看单个主机执行结果
                                            </button>
                                        </td>
                                    </tr>
                                {% endfor %}
                                </tbody>
                            </table>
                        {% else %}
                            <p>还没有执行记录！</p>
                        {% endif %}
                    </div>
                </div>
            </div>

            <!-- Host Detail Modal-->
            <div class="modal fade" id="Modal-host" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                <div class="modal-dialog" style="width:1200px;">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                            <h4 class="modal-title" id="myModalLabel">主机详情</h4>
                        </div>
                        <div class="modal-body">
                            <table id="mytable_host" class="display" width="100%" cellspacing="0">
                                <thead>
                                <tr>
                                    <th>主机id</th>
                                    <th>地区</th>
                                    <th>所在项目</th>
                                    <th>所在机房</th>
                                    <th>业务类型</th>
                                    <th>平台</th>
                                    <th>局域网IP</th>
                                    <th>电信ip</th>
                                    <th>联通ip</th>
                                    <th>用途</th>
                                    <th>执行结果</th>
                                    <th>详细</th>
                                </tr>
                                </thead>
                            </table>
                        </div>
                    </div><!-- /.modal-content -->
                </div><!-- /.modal-dialog -->
            </div>

            <!-- Execute Modal Detail-->
            <div class="modal fade" id="Modal-execute" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                <div class="modal-dialog" style="width:1000px;">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                            <h4 class="modal-title" id="myModalLabel">执行详情</h4>
                        </div>
                        <form>
                            <div class="modal-body" style="height:750px;overflow:auto;">
                                <input type="text" style="display: none" id="task_name" value="">
                                <textarea readonly rows="28" cols="100" style="min-width: 100%"
                                          id="execute_result"></textarea>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                            </div>
                        </form>
                    </div><!-- /.modal-content -->
                </div><!-- /.modal-dialog -->
            </div>

            <div id="is_superuser" data-is-superuser="{{ is_superuser }}"></div>

        </div>
    </div>
{% endblock %}
{% block bodyjs %}
    {% verbatim %}
    <script id="tpl" type="text/x-handlebars-template">
        {{#each func}}
        <button type="button" class="btn btn-sm btn-{{this.type}} btn-sm" onclick="{{this.fn}}">{{this.name}}</button>
        {{/each}}
    </script>
    {% endverbatim %}
    <script src="/static/js/handlebars-v3.0.1.js"></script>
    <script src="/static/js/jquery.dataTables.min.js"></script>
    <script src="/static/js/dataTables.colVis.js"></script>
    <script src="/static/js/salt_task_execute_history.js?v=20190517001"></script>
{% endblock %}
{% block css %}
    <link href="/static/css/jquery.dataTables.css" rel="stylesheet" type="text/css">
    <link href="/static/css/dataTables.colVis.css" rel="stylesheet" type="text/css">
    <link href="/static/css/system_cron_list.css" rel="stylesheet" type="text/css">
{% endblock %}
